package com.health.web.controller.teahouse;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.teahouse.domain.ExercisePlan;
import com.health.teahouse.service.IExercisePlanService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 运动计划管理Controller
 * 
 * @author yang
 * @date 2024-02-11
 */
@RestController
@RequestMapping("/teahouse/plan")
public class ExercisePlanController extends BaseController
{
    @Autowired
    private IExercisePlanService exercisePlanService;

    /**
     * 查询运动计划管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExercisePlan exercisePlan)
    {
        startPage();
        List<ExercisePlan> list = exercisePlanService.selectExercisePlanList(exercisePlan);
        return getDataTable(list);
    }



    /**
     * 导出运动计划管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:plan:export')")
    @Log(title = "运动计划管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExercisePlan exercisePlan)
    {
        List<ExercisePlan> list = exercisePlanService.selectExercisePlanList(exercisePlan);
        ExcelUtil<ExercisePlan> util = new ExcelUtil<ExercisePlan>(ExercisePlan.class);
        util.exportExcel(response, list, "运动计划管理数据");
    }

    /**
     * 获取运动计划管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:plan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(exercisePlanService.selectExercisePlanByPlanId(planId));
    }

    @GetMapping(value = "/getUser")
    public AjaxResult getUser()
    {
        return success(exercisePlanService.selectGetUser());
    }

    /**
     * 新增运动计划管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:plan:add')")
    @Log(title = "运动计划管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExercisePlan exercisePlan)
    {
        return toAjax(exercisePlanService.insertExercisePlan(exercisePlan));
    }

    /**
     * 修改运动计划管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:plan:edit')")
    @Log(title = "运动计划管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExercisePlan exercisePlan)
    {
        return toAjax(exercisePlanService.updateExercisePlan(exercisePlan));
    }

    /**
     * 删除运动计划管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:plan:remove')")
    @Log(title = "运动计划管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(exercisePlanService.deleteExercisePlanByPlanIds(planIds));
    }
}
